package com.scf.fruit.hospital.impl;

import com.scf.fruit.hospital.HospitalDto;
import com.scf.fruit.hospital.HospitalVisitDto;
import com.scf.fruit.hospital.HospitalVisitService;
import com.scf.fruit.hospital.dao.HospitalVisitMapper;
import com.scf.fruit.shiro.dao.FruitUserMapper;
import com.scf.fruit.util.IDUtil;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author : 孙超飞
 * @title :
 * @description :
 * @date : 2018-04-23 9:09
 */
@Service
public class HospitalVisitServiceImpl implements HospitalVisitService {
    @Resource
    private HospitalVisitMapper hospitalVisitMapper;
    @Override
    public List<HospitalVisitDto> queryList(HospitalVisitDto dto) {
        Example example=new Example(HospitalVisitDto.class);
        Example.Criteria criteria=example.createCriteria();
        criteria.andLike("hospitalName","%"+dto.getHospitalName()+"%");
        return hospitalVisitMapper.selectByExample(example);
    }

    @Override
    public Boolean insert(HospitalVisitDto dto) {
        dto.setId(IDUtil.getId());
        dto.setCreateTime(new Date());
        return hospitalVisitMapper.insert(dto)>1;
    }

    @Override
    public Boolean update(HospitalVisitDto dto) {
        if(null==dto.getId())
        {
            return false;
        }
        else {
            dto.setUpdateTime(new Date());
            return hospitalVisitMapper.updateByPrimaryKeySelective(dto)>1;
        }
    }

    @Override
    public Integer count(HospitalVisitDto dto) {
        Example example=new Example(HospitalVisitDto.class);
        Example.Criteria criteria=example.createCriteria();
        criteria.andLike("hospitalName","%"+dto.getHospitalName()+"%");
        return hospitalVisitMapper.selectCountByExample(example);
    }
}
